package com.yonyou.pmclouds.im.util;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadFactory;

/**
 * @Description:消息推送线程工厂类
 * 注：主要作用对线程属性进行定制化，方便问题回溯
 *
 * @Author: zhangwce
 * @Date: 2018/4/22 23:47
 */
@Slf4j
public class IMThreadFactory implements ThreadFactory {

    @Override
    public Thread newThread(Runnable r) {

        Thread imThread = new Thread(r);
        imThread.setName("IM推送线程");
        imThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                log.error("IM推送线程执行异常，具体信息为："+e.getMessage());
            }
        });

        return imThread;
    }
}
